package com.cybertron.ironhide.spider.plugin.impl;

import org.eweb4j.mvc.Http;

import com.cybertron.ironhide.spider.SpiderListener;
import com.cybertron.ironhide.spider.fetcher.FetchRequest;
import com.cybertron.ironhide.spider.fetcher.FetchResult;
import com.cybertron.ironhide.spider.plugin.FetchPoint;
import com.cybertron.ironhide.spider.plugin.util.PageFetcherImpl;
import com.cybertron.ironhide.spider.task.Task;
import com.cybertron.ironhide.spider.xml.Site;

/**
 * 一个Host一个FetchPointImpl对象
 * 
 * @author weiwei l.weiwei@163.com
 * @date 2013-1-7 下午06:40:05
 */
public class FetchPointImpl implements FetchPoint {

	public void init(Site site, SpiderListener listener) {

	}

	public void destroy() {
	}

	public FetchResult fetch(Task task, FetchResult result) throws Exception {
		Site site = task.site;
		PageFetcherImpl fetcher = new PageFetcherImpl(site);

		String url = task.url.replace(" ", "%20");

		FetchRequest req = new FetchRequest();
		req.setUrl(url);
		req.setHttpMethod(Http.Method.GET);

		return fetcher.fetch(req);
	}
}
